var pictures = new Array('p10.png','p1.png','p10.png','p1.png','p10.png','p1.png');
var functions = new Array('func1()', 'func2()', 'func3()', 'func4()', 'func5()', 'func6()');
var items = pictures.length;
var angles = new Array(items);
var images = new Array(items);
var rx = 200;
var ry = 50;
var cx = 0;
var cy = 0;
var speed = 0.005;

function itemSize()
{
for(var i = 0; i < items; i++)
{
images[i] = new Image();
images[i].src = pictures[i];
}
initCar();
}

function initCar()
{
var content = document.getElementById('content');
for(var i = 0; i < items; i++)
{
angles[i] = ((Math.PI * 2) / items) * i;
var xpos = (Math.cos(angles[i]) * rx) + cx;
var ypos = (Math.sin(angles[i]) * ry) + cy;
var obj = newObj(i, xpos, ypos, parseInt(ypos), pictures[i]);
content.innerHTML += obj;
}
setInterval('rotateCar()', 5);
}

function rotateCar()
{
for(var i = 0; i < items; i++)
{
angles[i] += speed; //radians
var xpos = (Math.cos(angles[i]) * rx) + cx;
var ypos = (Math.sin(angles[i]) * ry) + cy;
var obj = document.getElementById('obj' + i);
obj.style.left = xpos + 'px';
obj.style.top = ypos + 'px';
obj.style.zIndex = parseInt(ypos);

var objImg = document.getElementById('img' + i);
var delta = (ypos - cy + ry) / (2 * ry);
delta = (delta + 1) / 2;
objImg.style.height = (delta * images[i].height) + 'px';
objImg.style.width = (delta * images[i].width) + 'px';

}
}

function newObj(id, x, y, z, src)
{
return '<div id="obj' + id + '" onclick="clickItem(' + id + ')" style="position:absolute; left:' + x + 'px; top:' + y + 'px; z-index:' + z + '; width:100px;"><img id="img' + id + '" src="' + src + '" /></div>';
}

function clickItem(id)
{
eval(functions[id]);
}

function func1()
{
alert('Item 1');
}

function func2()
{
alert('Item 2');
}

function func3()
{
alert('Item 3');
}

function func4()
{
alert('Item 4');
}

function func5()
{
alert('Item 5');
}

function func6()
{
alert('Item 6');
}


